package leetcode.offer;

/**
 * ClassName: Offer56I_SingleNumbers
 * Description: leetcode-剑指offer 56 - I 数组中数字出现的次数
 * date: 2021-11-17 21:45
 *
 * @author liyifan
 */
public class Offer56I_SingleNumbers {
    public int[] singleNumbers(int[] nums) {
        int x = 0,y = 0;
        int m = 1, n = 0;
        for (Integer num : nums) {
            n ^= num;
        }
        while ((m & n) == 0) {
            m <<= 1;
        }
        for (Integer num:nums) {
            if ((m & num) == 0)
                x ^= num;
            else
                y ^= num;
        }
        return new int[]{x, y};

    }
}
